<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    #include("common/header.html")
</head>

<body>
<div style="margin: 15px;">
    <div class="layui-form" id="form">
        <div class="layui-form-item">
            <label class="layui-form-label">封面图片</label>
            <div class="layui-input-block">
                <img id="imgUrl" src="/admin$!info.imgUrl" data-src="$!info.imgUrl" height="200px" width="200px">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
                <input type="file" name="file" id="imgFile" class="layui-upload-file">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-block">
                <input type="text" id="title" value="$!info.title" is-yz="true" yz-type="null"  lay-verify="title" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">分类</label>
            <div class="layui-input-block">
                <input type="text" id="type" value="$!info.type" is-yz="true" yz-type="null"  lay-verify="title" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">上传视频</label>
            <div class="layui-input-block">
                <input type="file" name="file" lay-type="video" id="vedioFile" class="layui-upload-file">
                <input type="hidden" id="url" value="$!info.url" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否收费</label>
            <div class="layui-input-block">
                #if($!info.isMoney == 1)
                <input type="checkbox" name="money" lay-filter="money" lay-skin="switch" lay-text="是|否" checked>
                #else
                <input type="checkbox" name="money" lay-filter="money" lay-skin="switch" lay-text="是|否">
                #end
                <input type="hidden" id="isMoney" value="$!info.isMoney" />
            </div>
        </div>
        #if($!info.isMoney == 1)
        <div class="layui-form-item" id="moneyDiv">
            <label class="layui-form-label">收费金额</label>
            <div class="layui-input-block">
                <input type="text" id="money" value="$!info.money" class="layui-input" >
            </div>
        </div>
        #else
        <div class="layui-form-item" style="display: none;" id="moneyDiv">
            <label class="layui-form-label">收费金额</label>
            <div class="layui-input-block">
                <input type="text" id="money" value="$!info.money" class="layui-input" >
            </div>
        </div>
        #end
    </div>
</div>
<script>

    var layer;
    var form;
    layui.use(['layer','form', 'upload'], function () {
        layer = layui.layer;
        form = layui.form()

        layui.upload({
            url: '/admin/upload/',
            elem: '#imgFile',
            success: function (res) {

                layer.msg(res.msg);

                if(res.code == -1){
                    return;
                }

                $("#imgUrl").attr("src","/admin" + res.data);
                $("#imgUrl").attr("data-src",res.data);
                console.log(res); //上传成功返回值，必须为json格式
            }
        });

        layui.upload({
            url: '/admin/upload/',
            elem: '#vedioFile',
            success: function (res) {

                layer.msg(res.msg);

                if(res.code == -1){
                    return;
                }
                console.log(res); //上传成功返回值，必须为json格式
                $("#url").val(res.data);
            }
        });

        //监听指定开关
        form.on('switch(money)', function(data){
//            console.log(this.checked);
            if(this.checked){
                $("#moneyDiv").show();
                $("#isMoney").val(1);
            }else{
                $("#moneyDiv").hide();
                $("#isMoney").val(0);
                $("#money").val(0);
            }
        });
    });

</script>
</body>

</html>